﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace AsyncReturnValueTpye
{
     static  class DoAsyncStuffTaskGeneric
    {
        private static int Der(int x, int y)
        {
            return x - y;
        }
        //异步任务
        private static async Task<int> CalculateAsync(int x, int y)
        {
            int der = await Task.Run(() => Der(x, y));
            return der;
        }

        static public void CallAsyncMethodReturnTaskGenric()
        {
            Console.WriteLine("调用异步方法");
            Task<int> value = CalculateAsync(10, 6);

            Console.WriteLine($"返回: {value.Result}");
            Console.WriteLine("其它处理");
        }



        // private static int GetSum(int x, int y)
        // {
        //     return x + y;
        // }
        // private static async Task<int> CalculateSumAsync(int x, int y)
        // {
        //     int sum = await Task.Run(() => GetSum(x, y));
        //     return sum;
        // }

        //static public void CallAsyncMethodReturnTaskGenric()
        // {
        //     Console.WriteLine("调用返回值为Task<T>的异步方法");
        //     Task<int> value =CalculateSumAsync(5, 6);
        //     //（如有需要） 此处可以做其它事情 ...          
        //     Console.WriteLine($"Task<T>: {value.Result}" );
        //     Console.WriteLine("其它处理1");
        // }

    }
}
